<template>
	<view class="container">
		
		<view class="flex-between row boxPanel ">
		  <view class="">手机号</view>
		  <view class="flex-y-center" >
		    <input type="number" placeholder="请输入手机号" placeholder-class="inputs" v-model="phone" style="text-align: right;" maxlength="11">
		  </view>
		</view>
		
		<view class="footer fixfooter" :class="{ 'bottom-safe-area': isIphoneX }">
			<view class="submit" @click="submit">保存</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				phone: ''
			}
		},
		onLoad(data) {
		  this.isIphoneX = this.$util.uniappIsIPhoneX()
		  if(data.id) {
			this.id = data.id;
		  }
		  this.getData();
		},
		methods: {
			getData() {
				this.$api.sendRequest({
					url: "/api/userHealth/getDeviceContacts",
					data: {
						id: this.id,
						type: 2,
					},
					success: res => {
						if(res.code == 0) {
							if(res.data.contact_phone !== null && res.data.contact_phone !== '') {
								this.phone = res.data.contact_phone;
							}
						} else {
							this.$util.showToast({title: res.message});
						}
					}
				})
			},
			submit() {
				
				uni.showLoading({
					title: '提交中...'
				});

				var data = {
					id: this.id,
				}

				data.phone = this.phone

				this.$api.sendRequest({
					url: "/api/userHealth/setContact",
					data: data,
					success: res => {
						uni.hideLoading();
						if(res.code == 0) {
							uni.showToast({
								title: '设置成功',
								icon: 'success'
							});
							setTimeout(() => {
								uni.navigateBack();
							}, 1500);
						} else {
							this.$util.showToast({title: res.message});
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
.boxPanel {
	padding: 40rpx 24rpx;
}
.row {
	.inputs {
		font-size: 28rpx;
		color: #B8BAC2;
	}
}
</style>
